#include <stdlib.h>
#include <stdio.h>
#include "htsmsg.h"

extern char peer0_0[];

void buffer2htsmsg() {
        HTSMSG* htsmsg = htsmsgFromBuffer(peer0_0);
        size_t index = 0;

        for (; index < htsmsg->num_fields; index++) {
                HTSMSG_FIELD* field = htsmsg->fields[index];
                printf("name:[%.*s]\n", field->name_len, field->field);
        }

        htsmsgFree(htsmsg);
}

void htsmsg2buffer() {
        HTSMSG* htsmsg = HTSMSG_HELLO();
        HTSMSG_CLIENT_SEQ(htsmsg, 1);
        HTSMSG_CLIENT_USERNAME(htsmsg, "admin");

        htsmsgFieldsToBuffer(htsmsg);

        htsmsgFree(htsmsg);
}

int main(void) {

        buffer2htsmsg();
        htsmsg2buffer();

        return EXIT_SUCCESS;
}

